<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>书籍信息总览</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script>
        function deleteConfirm(bookID) {
            if (window.confirm("确定删除该书籍吗？")) {
                document.location.href = "${pageContext.request.contextPath}/book/deleteBook?bookID=" + bookID;
            }
        }
    </script>

    <style>
        table {
            table-layout: fixed;
        }

        td:nth-child(4) {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

    </style>

</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <c:if test="${queryMessage == null}">
                        <a href="${pageContext.request.contextPath}/user/toUserInforPaper?email=${sessionScope.userMessage.email}">
                            <img src="${user.profilePath}" alt="" class="img-circle" width="90px" height="90px"
                                 title="我的头像">
                        </a>
                    </c:if>

                    <c:choose>
                        <c:when test="${sessionScope.userMessage.authority == 'super'}">
                            <small>${user.userName} 超级管理员您好</small><br><br>
                        </c:when>
                        <c:when test="${sessionScope.userMessage.authority == 'admin'}">
                            <small>${user.userName} 管理员你好</small><br><br>
                        </c:when>
                        <c:when test="${sessionScope.userMessage.authority == 'general'}">
                            <small>${user.userName} 读者你好</small><br><br>
                        </c:when>
                    </c:choose>
                    <small>书籍总览：</small>
                </h1>
            </div>
        </div>

        <div class="row">
            <div class="col-md-4 column">
                <a class="btn btn-danger" href="${pageContext.request.contextPath}/door/logout">退出系统</a>
                <c:if test="${queryMessage == null && sessionScope.userMessage.authority == 'general'}">
                    <a class="btn btn-success" href="${pageContext.request.contextPath}/borrow/toMyBorrow?borrowerEmail=${sessionScope.userMessage.email}">我的申请</a>
                </c:if>
                <c:if test="${queryMessage == null && sessionScope.userMessage.authority != 'general'}">
                    <a class="btn btn-success" href="${pageContext.request.contextPath}/borrow/toAllBorrow">借阅管理</a>
                </c:if>
                <c:if test="${queryMessage == null && sessionScope.userMessage.authority == 'super'}">
                    <a class="btn btn-success" href="${pageContext.request.contextPath}/user/toUserPaper">用户管理</a>
                </c:if>
                <c:if test="${queryMessage == null && sessionScope.userMessage.authority != 'general'}">
                    <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddPaper">新增书籍</a>
                </c:if>
                <c:if test="${queryMessage != null}">
                    <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/query">回到主页面</a>
                </c:if>
            </div>
            <div class="col-lg-8 column text-right">
                <form class="form-inline" action="${pageContext.request.contextPath}/book/queryBookByName"
                      method="post">
                    <span style="color: red; font-weight: bold">${queryMessage}</span>
                    <input type="text" class="form-control" name="queryBookName" placeholder="请输入查询的图书名称" required>
                    <button type="submit" class="btn btn-primary">查询书籍</button>
                </form>
            </div>
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-hover table-striped">
                <thead>
                <tr>
                    <th>书籍序号</th>
                    <th>书籍名称</th>
                    <th>书籍类型</th>
                    <th>书籍摘要</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="book" items="${bookList}" varStatus="bookStatus">
                    <tr>
                        <td>${bookStatus.count}</td>
                        <td>${book.bookName}</td>
                        <td>${book.bookType}</td>
                        <td>${book.detail}</td>
                        <td>
                            <c:if test="${sessionScope.userMessage.authority != 'general'}">
                                <a class="btn btn-info"
                                   href="${pageContext.request.contextPath}/book/toUpdatePaper?bookID=${book.bookID}">修改</a>
                                &nbsp;
                                <a class="btn btn-danger" href="javascript:void(0);"
                                   onclick="deleteConfirm('${book.bookID}')">删除</a>
                                &nbsp;
                            </c:if>
                            <a class="btn btn-warning"
                               href="${pageContext.request.contextPath}/book/toDetailPaper?bookID=${book.bookID}">详情</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
</div>

</body>
</html>
